<?php

include_once 'DB.php';

class Application_Model_Comments extends Application_Model_DB {

    public function addComment($page_id, $name, $comment) {
        $sql = "INSERT INTO `comments` SET
                    `page_id` = '".(int)$page_id."',
                    `name` = '".addslashes(strip_tags($name))."',
                    `comment` = '".  addslashes(strip_tags($comment))."'
            ";
        return $this->Exec($sql);
    }

    public function getComments($page_id, $order = "ASC"){
        $sql =  "SELECT `name` , `comment`, `date_create`
                    From `comments`
                 WHERE `page_id` = " . (int)$page_id .
                 ' ORDER BY `date_create` ' . $order;
        return $this->GetAll($sql);
    }

    public function getCntComments($page_id){
        $sql =  "SELECT count(`id`)
                    From `comments`
                 WHERE `page_id` = " . (int)$page_id;
        return $this->GetOne($sql);
    }

}